<script type="text/javascript">
$(document).ready(function(){
	$('#oPendding').click(function(){
		
		var arr = getCheck();
		//alert(arr.length);
		$("#orders").val(arr);
		$("#ordertype").val(1);
		$("form#oform").submit();
	});

	$('#oPendding2').click(function(){
		
		var arr = getCheck();
		//alert(arr.length);
		$("#orders").val(arr);
		$("#ordertype").val(12);
		$("form#oform").submit();
	});

	$('#oUnlockd').click(function(){
		var arr = getCheck();
		$("#orders").val(arr);
		$("#ordertype").val(2);
		$("form#oform").submit();
	});

	$('#oRefund').click(function(){
		var arr = getCheck();
		$("#orders").val(arr);
		$("#ordertype").val(3);
		$("form#oform").submit();
	});
	$('#ocheckall').click(function(){
		//alert($(':checkbox').length);
		$('table#o-table :checkbox').each(function(){	
		if($(this).is(':checked'))
			$(this).removeAttr('checked',false);	
		else
			$(this).attr('checked',true);
		});
	});

	$('#pcheckall').click(function(){
		//alert($(':checkbox').length);
		$('table#p-table :checkbox').each(function(){	
		if($(this).is(':checked'))
			$(this).removeAttr('checked',false);	
		else
			$(this).attr('checked',true);
		});
	});
	
});


function getCheck(){
	var check = document.getElementsByTagName('input');
	var vals = [];
	var count = 0;
	var str = "";
	for(var i = 0; i < check.length; i++){
		if(check[i].type == 'checkbox' && check[i].checked==true){
			vals[count] = check[i].id + "";
			count++;
			str = str + check[i].id + ",";
		}
	}

	return str;
}
</script>

<?php
$this->breadcrumbs=array(
	'Danh sách ­ Order',
); 
?>
<h1>Quản lý thông tin Order</h1>

<form id='oform' name='oform' method='post' action ='<?php echo $this->createUrl("dichvu/orderadmin",array('type'=>'order') ); ?>'>
	<input id='orders' name='orders' type='hidden'/>
	<input id='ordertype' name='ordertype' type='hidden'/>
</form>

<div class='full-creen'>
	<?php echo CHtml::button("Pendding 1", array('id'=>'oPendding')); ?>
	<?php echo CHtml::button("Pendding 2", array('id'=>'oPendding2')); ?>
	<?php echo CHtml::button("Unlock", array('id'=>'oUnlockd')); ?>
	<?php echo CHtml::button("Refund", array('id'=>'oRefund')); ?>
	<?php echo CHtml::link("Export", array('dichvu/exportorder','trangthai'=>0)); ?>
	<div class='m-paging'> <?php $this->widget('MyPage', array('pages' => $listorders['pages'])) ;?></div>
</div>

<div class='full-creen'>
	<div class='right-box-item'>
		<h1>Danh sách ­ Order</h1>
	
	<div class='main-content'>
		<table id='o-table'>
		
			<tr class='header-table'>
				<th width='180px'>IMEI</th>
				<th width='120px'>User</th>
				<th width='200px'>Nhà mạng</th>
				<th width='50px' align='center'>Giá</th>
				<th width='120px'>Ngày order</th>
				<th width='80px'>
				<a href='#' id='ocheckall' style='color:blue;'>Check All</a>
				</th>
				<th width='100px'>
					Khác
				</th>
			</tr>
		<?php
		foreach ( $listorders['orders'] as $value){
			echo "<tr class='row-table'>";
			echo "<td>". $value->noidung. "</td>";
			echo "<td>". $value->tbuser->username." </td>";
			echo "<td>".$value->tbdichvu->tbnhomdichvu->tennhom." - ". $value->tbdichvu->tendichvu. "</td>";
			echo "<td style='text-align:center'>". $value->gia. "</td>";
			echo "<td>". $value->ngaymua. "</td>";

			echo "<td>". CHtml::CheckBox($value->id,'', array (
		                                        'checked'=>'checked',
		                                        'value'=>'on',
		                                        )). "</td>";
		    echo "<td>". CHtml::link('Trả code', array('dichvu/tracode', 'id'=> $value->id)). "</td>";
			echo "</tr>";
		}
		?>
		</table>
	</div>
	</div>
</div>